package com.corpgovernment.organization.controller;

import com.corpgovernment.common.base.BaseUserInfo;
import com.corpgovernment.common.base.JSONResult;
import com.ctrip.corp.obt.generic.core.context.UserInfoContext;
import com.ctrip.corp.obt.generic.utils.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;

@RequestMapping(value = "/usertest")
@RestController
@Slf4j
public class UserInfoTestController {

    @RequestMapping(value = "/getUserInfo")
    public JSONResult<String> getUserInfo(HttpServletRequest request, BaseUserInfo userInfo, String token_id,@RequestParam String corp_code) {
        String uri = request.getRequestURI();
        Enumeration enumeration = request.getParameterNames();
        StringBuilder sb = new StringBuilder();
        while (enumeration.hasMoreElements()) {
            String paramName = (String) enumeration.nextElement();
            String paramValue = request.getParameter(paramName);
            sb.append(paramName).append("=").append(paramValue).append("&");
        }
        log.info("用户信息为1：{}", sb.toString());
        String tokenId = request.getParameter("token_id");
        String source = request.getParameter("source");
        log.info("用户信息为2：{}，{}", tokenId, source);
        log.info("用户信息为3：{}", userInfo);
        log.info("用户信息为4：{}", request.getParameter("userInfo"));
        log.info("用户信息为5：{}", request.getParameterMap());
        log.info("用户信息为6：{}，{}", token_id, corp_code);
        BaseUserInfo contextParams = UserInfoContext.getContextParams(BaseUserInfo.class);//参数校验
        log.info("用户信息为7：{}，{}", JsonUtils.toJsonString(contextParams));
        return new JSONResult<>(sb.toString() + "|" + tokenId + ":" + source);
    }
}
